﻿//#define SingleMA
//#define FG


 

namespace Orid.Management.Statistics.Tools.Decomposition.Logic
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using DecompositionData = Orid.Management.Statistics.Tools.Decomposition.Data;
    using DecompositionModel= Orid.Management.Statistics.Tools.Decomposition.Model;
    using Orid.Management.Common.Job;
   
     
    public class DecompositionManage
    {  
        UI.FormManageDecompositionOrders ParentForm;

        WorkMode workMode = WorkMode.Offline;

        #region 构造函数 


        public DecompositionManage(    UI.FormManageDecompositionOrders parentForm)
        {

            if (!Convert.ToBoolean(Config.Setting.SettingInstance.Offline))
            {
                workMode = WorkMode.Online;
            }
            this.ParentForm = parentForm;
        }

        #endregion

        #region 分解受番获得 通过查询视图

        public DataSet GetDecompositionOrders(DateTimeOffset? starTime,DateTimeOffset? finishTime)
        {
            DecompositionData.DecompositionOrders decompositionOrders;

            if (workMode == WorkMode.Offline)
            {
                decompositionOrders = new DecompositionData.DecompositionOrdersOffline();
            }
            else
            {
                decompositionOrders = new DecompositionData.DecompositionOrdersOnline(); 
            }
            DataSet DSDecompositionOrders;
            try
            {
                if ((starTime == null) && (finishTime == null))
                {
                    DSDecompositionOrders = decompositionOrders.GetAllOrders();

                }
                else
                {
                    DSDecompositionOrders = decompositionOrders.GetDecompositionOrders(starTime, finishTime);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

             return DSDecompositionOrders;

        }

         public DataSet GetDecompositionOrders(List<Guid> orders )
         {
             DecompositionData.DecompositionOrders decompositionOrders;

             if (workMode == WorkMode.Offline)
             {
                 decompositionOrders = new DecompositionData.DecompositionOrdersOffline();
             }
             else
             {
                 decompositionOrders = new DecompositionData.DecompositionOrdersOnline();
             }
             DataSet DSDecompositionOrders;
             try
             {


                 DSDecompositionOrders = decompositionOrders.GetDecompositionOrders(orders);
                 
             }
             catch (Exception ex)
             {
                 throw ex;
             }

             return DSDecompositionOrders;
         }


        #endregion

        #region 主方法 线程入口

        public void DecomposeAll(object orderIdList)
        {
             List<Guid> list = orderIdList as List<Guid>;

                foreach (Guid item in list)
                {
                    if (ParentForm.IsAutoRun)
                    {
                        Decompose(item);                      

                    }
                }


               
                UI.DecompostiteFinish decompostiteFinish = new UI.DecompostiteFinish(this.ParentForm.OnDecompositionFinished);
                this.ParentForm.Invoke(decompostiteFinish);
         
            
        }

        private void Decompose(object orderId)
        {
 
            Guid orderID = ((Guid)orderId);
 
               

                if (workMode == WorkMode.Offline)
                {

                    OfflineDecomposeImage(orderID);
                }
                else
                {
                    OnlineDecomposeImage(orderID);
                }


         



            UI.DecompostiteEnd decompostiteEnd = new  UI.DecompostiteEnd (  this.ParentForm.DecompostiteEnd);
            this.ParentForm.Invoke(decompostiteEnd, new Object[] { orderID });

 
        }


        #endregion

        #region 在线 离线分解方法

        /// <summary>
        /// 在线分解数据
        /// </summary>
        /// <param name="orderId"></param>
         private void OnlineDecomposeImage(Guid orderId)
         { 

                 DecompositionData.Order order = new DecompositionData.OrderOnline();
                 DecompositionModel.ModelOrder modelOrder = order.GetOrderItem(orderId);
                 string dataAddress = modelOrder.DataDBAddress;
                 string jobAddress = modelOrder.JobDBAddress;

                 DecomposeImage(
                    modelOrder,
                     order,
                     new DecompositionData.ParentDataOnline(dataAddress),
                     new DecompositionData.ChildDatdaOnline(dataAddress),
                     new DecompositionData.JobOnline(jobAddress),
                     new DecompositionData.DistributeOnline(jobAddress),
                     new DecompositionData.JobLogOnline(jobAddress) 

                     );
     
         }
     
        /// <summary>
        /// 离线分解数据
        /// </summary>
        /// <param name="orderId"></param>
        private  void OfflineDecomposeImage(Guid orderId)
        {
            //try{

            DecompositionData.Order order = new DecompositionData.OrderOffline();

             DecomposeImage(
                 order.GetOrderItem(orderId),
                 order,
                 new DecompositionData.ParentDataOffline(),
                 new DecompositionData.ChildDatdaOffline(),
                 new DecompositionData.JobOffline(),
                 new DecompositionData.DistributeOffline(),
                 new DecompositionData.JobLogOffline()
                 );
                       
           


        }

        #endregion
        
        #region 分解数据

        private void DecomposeImage(
            DecompositionModel.ModelOrder modelOrder,
            DecompositionData.Order order,
            DecompositionData.ParentData parentData,
            DecompositionData.ChildData childData,
            DecompositionData.Job job,
            DecompositionData.Distribute distribute,
            DecompositionData.JobLog jobLog
            )
        {

            Guid errorImageId =Guid.Empty;

            try
            {
             

                Guid StaticID = Guid.NewGuid();

                Guid orderId = modelOrder.OrderID;


                string starMsg = "DecompositeStar @" + System.DateTime.Now.ToLongTimeString() + "--" + orderId.ToString();
                Logic.Log.Info(starMsg);
                writeMsg(starMsg);
   
                #region 父画像
                //-------处理父画像
              
                //受番的父画像信息
                List<DecompositionModel.ModelParentObject> listModelParentData = parentData.GetParentDatas(orderId);

                //异常信息检查
                if (listModelParentData.Count == 0)
                {
                    modelOrder.AddException("ParentDataCountException", "父画像数量为零。" + "orderID=" + orderId.ToString());
                }
                //-------处理父画像结束

                #endregion

                #region 获得全部子画像

                //受番中全部子画像
                List<DecompositionModel.ModelOrderRecord> listOrderRecord = childData.GetChildID(orderId);
                //异常信息检查
                if (listOrderRecord.Count == 0)
                {
                    modelOrder.AddException("OrderCountException", "受番数量为零。"+"orderID="+orderId.ToString()  );
                }
                #endregion

                #region 变量定义

                //FrameList
                List<DecompositionModel.ModelFrameObject> listFrameObject = new List<DecompositionModel.ModelFrameObject>();
                //BlockList
                List<DecompositionModel.ModelBlockObject> listBlockObject = new List<DecompositionModel.ModelBlockObject>();
                //JudgeList
                List<DecompositionModel.ModelJudgeObject> listJudgeObject = new List<DecompositionModel.ModelJudgeObject>();
                //InputList
                List<DecompositionModel.ModelInputObject> listInputObject = new List<DecompositionModel.ModelInputObject>();
                //JobCancelLogsList
                List<DecompositionModel.ModelJobLog> listJobLog = new List< Decomposition.Model.ModelJobLog>();

                //FrameResultList
                //2010-12-20
                List<DecompositionModel.ModelFrameResult> listFramtResult = new List<Decomposition.Model.ModelFrameResult>();

                #endregion

                int iRecordCount = listOrderRecord.Count ;
                int iRecord = 0;
                writeMsg("ImageCount :" + iRecordCount);

                #region 找到受番全部的子画像

                //找到属于此受番的所有的子画像相对的处理结果
                foreach (DecompositionModel.ModelOrderRecord itemOrderRecord in listOrderRecord)
                {

         

                    Guid childImageId = itemOrderRecord.ChildDataID;
                    errorImageId = childImageId;

                    int categoryId = itemOrderRecord.CategoryID;

                    #region 主线程消息传递
                    
                    iRecord++;
                    SetProcessBarMain(iRecord, iRecordCount);
                    writeMsg("ImageID：" + itemOrderRecord.ChildDataID.ToString() + "  " +
                                ((Category)(itemOrderRecord.CategoryID)).ToString() +
                        "  " + iRecord + "/" + iRecordCount);

                   // Log.Info(childImageId.ToString());

                    #endregion


                    if (itemOrderRecord.ChildDataID.ToString().ToLower().Equals("36c31f21-6d58-4b7a-a9d6-b83051558cb0".ToLower()))
                    {
                        string ab = "";
                    }


                    if ( (categoryId == (int)Category.FrameObject  )|| (categoryId == (int)Category.ParentObject ) )
                    {
                        #region FrameObject

                        DecompositionModel.ModelFrameObject temp = childData.GetFrameData(childImageId);
                        if (temp !=null)
                            listFrameObject.Add(temp);

                        #endregion


                    }
                    
                    if (categoryId == (int)Category.BlockObject)
                    {
                        #region BlockObject

                        DecompositionModel.ModelBlockObject temp = childData.GetBlockData(childImageId);

                        if (temp != null)
                            listBlockObject.Add(temp);

                        #endregion 
                    }
                    
                    if (categoryId == (int)Category.JudgeObject)
                    {
                        #region JudgeObject

                        DecompositionModel.ModelJudgeObject temp = childData.GetJudgeData(childImageId);
                        if (temp != null)
                            listJudgeObject.Add(temp);

                    
                        #endregion


                    }
                   //候补判定
                    if ( (categoryId == (int)Category.InputObject)  )  
                    {
                        #region inputObject

                        DecompositionModel.ModelInputObject temp = childData.GetInputObject(childImageId);
                        if (temp != null)
                        {
                            listInputObject.Add(temp);
                        }
                        
                        /* 以下内容从属性中获得
                        if (temp != null)  
                        {
                            temp.FrameId = childData.GetParentID(temp.BlockId);



                            //印刷类型的
                            //本身对象就是Row
                            //坐标值需要row的Parent对象 Block的坐标

                            //先找Block对象坐标
                            DecompositionModel.ModelInputObject blockObject = childData.GetInputObject(temp.BlockId);

                           
                            if (blockObject != null)
                            {
                                //通过Frame来查找
                                BlockImage blockImage = childData.GetBlockImage(
                                    temp.FrameId,
                                    blockObject.X, blockObject.Y, blockObject.Width, blockObject.Height);

                                if (blockImage != null)
                                {
                                    temp.WordDirection = blockImage.WordDirection.ToString();
                                    temp.WordType = blockImage.WordType.ToString();
                                    temp.ScriptType = blockImage.ScriptType.ToString();


                                   
                                }
                            }
                            
                        }
                      */ 


                        #endregion

                    }
                    
                    if ( (categoryId == (int)Category.手書) || (categoryId == (int)Category.BlockObject) )
                        
                    {
                        
                        #region inputObject

                       DecompositionModel. ModelInputObject temp = childData.GetInputObject(childImageId);
                       if (temp != null)
                       {  listInputObject.Add(temp);}
                        /* 以下内容从属性中获得
                        if (temp != null)
                        {
                            //手书类型的
                            //本身对象就是block
                            //通过Frame来查找
                            BlockImage blockImage = childData.GetBlockImage(temp.FrameId, temp.X, temp.Y, temp.Width, temp.Height);
                           
                            if (blockImage != null)
                            {
                                temp.WordDirection = blockImage.WordDirection.ToString();
                                temp.WordType = blockImage.WordType.ToString();
                                temp.ScriptType = blockImage.ScriptType.ToString(); 
                                temp.MatterType = blockImage.MatterType.ToString();

                                listInputObject.Add(temp);
                            }
                        }
                        
                       */ 
                        #endregion

                    }
                    
                    if (categoryId == (int)Category.非文字)
                    {
                        //当categoryid 等于0时 (非文字，著作权，录入不要)
                        //不再进行录入，当前结果中仅包含trimer结果
                        //如果存在trimer结果，需要把trimer结果记录下来保存到blockobject里面
                        //被记录的block结果中没有jobid，因为还没有对block进行处理。

                        #region BlockObject

                        DecompositionModel.ModelBlockObject temp = childData.GetBlockData(childImageId);

                        if (temp != null)
                        {
                            temp.JobClass = JobClassAll.Trimer;
                            listBlockObject.Add(temp);
                        }


                        #endregion
                    }
                    
                    if  (categoryId == (int)Category.FrameResult)
                    {
                        #region FrameResult

                        List<DecompositionModel.ModelFrameResult> temp = childData.GetFrameResult(childImageId);

                        if (temp != null)
                            listFramtResult.AddRange(temp);

                        #endregion
                    }

                }

                

                #endregion

                #region 找到配信的job

                //数据不全
                List<DecompositionModel.ModelJob> listJob = distribute.GetJobsFromDistributes(orderId);
                for (int i = 0; i < listJob.Count; i++)
                {
                    DecompositionModel.ModelJob itemJob = listJob[i];
                    FillJobItem(ref itemJob, job);
                }
                
                   

#if  FG 
                //如果需要从上传的job中获得录入历史 添加条件编译在 项目属性>Build选项卡>General  FG
                #region 图像数据被清空 从上传job中获得数据
                    ////
                bool gFind = false;
                //经过了Fjob的子画像

                foreach (DecompositionModel.ModelJob fJobitem in listJob.FindAll(child => child.JobClassID == 16))
                {

                    foreach (DecompositionModel.ModelJob.ImageData itemFImageData in fJobitem.ChildImage)
                    {
                        DecompositionModel.ModelFrameResult frameResult = new Orid.Management.Statistics.Tools.Decomposition.Model.ModelFrameResult();
                        frameResult.FrameResultID = itemFImageData.ChildDataID;
                        frameResult.OrderID = modelOrder.OrderID;

                        Data.UploadJobStore jobStor = new Orid.Management.Statistics.Tools.Decomposition.Data.UploadJobStoreOnline(modelOrder.DataDBAddress);

                        //寻找F结果
                        jobStor.GetFGEntryResult(fJobitem.JobID, fJobitem.AccountID, ref frameResult);
                        //frameImageIDList.Add(  itemFImageData.ChildDataID);

                        //FChildIamgeId is

                        //GChildIamgeId is
                        gFind = false;
                        foreach (DecompositionModel.ModelJob gJobitem in listJob.FindAll(child => child.JobClassID == 17))
                        {
                            foreach (DecompositionModel.ModelJob.ImageData itemGImageData in gJobitem.ChildImage)
                            {
                                if (itemGImageData.ChildDataID == itemFImageData.ChildDataID)
                                {
                                    gFind = true;
                                    break;

                                }

                            }

                            if (gFind)
                            {
                                //寻找G结果
                                jobStor.GetFGEntryResult(gJobitem.JobID, gJobitem.AccountID, ref frameResult);
                            }
                        }
                        listFramtResult.Add(frameResult);
                    }
                } 
                #endregion
#endif


                #endregion

                int jobCount = listJob.Count ;
                iRecord = 0;

                writeMsg("JobCount :" + jobCount);

                #region 循环job

                for (int i = 0; i < listJob.Count; i++)
                {
                    DecompositionModel.ModelJob itemJob = listJob[i];

                    //string abc;
                    //if (itemJob.JobID.ToString().ToLower() == "0C517009-AC9D-4467-8375-ACCB4AF78A7D".ToLower())
                    //{
                    //    abc = "";
                    //}
                    listJobLog.AddRange( jobLog.GetJobLog( itemJob.JobID,itemJob.DownLoadID)  );

                    #region 补充job信息

                    //补充其他信息
                    FillJobItem(ref itemJob, job);

                    #endregion 

                    //
                    iRecord++;
                    SetProcessBarMain(iRecord, jobCount);
                    string jobMSG = "JobID:" + itemJob.JobID.ToString() + "  " +
                        ((Category)itemJob.CateGoryID).ToString() + "  " +
                        iRecord + "/" + jobCount;
                    writeMsg(jobMSG);


                    Log.Info(jobMSG);
                  


                    #region 循环全部子画像 回写job 画像内容

                    foreach (DecompositionModel.ModelJob.ImageData itemImageData in itemJob.ChildImage)
                    {
                        Guid childDataID = itemImageData.ChildDataID;

               
                        if (itemJob.CateGoryID == (int)Category.FrameObject || itemJob.CateGoryID == (int)Category.ParentObject) 
                        {
                            
                            SetFormObjectInfo(ref itemJob, ref listFrameObject, childDataID);
                            
                        }
                        else if (itemJob.CateGoryID == (int)Category.BlockObject)
                        {
                           
                            SetBlockObjectInfo(ref itemJob, ref listBlockObject, childDataID);
                            SetInputObjectInfo(ref itemJob, ref listInputObject, childDataID);
                            

                        }
                        else if (itemJob.CateGoryID == (int)Category.JudgeObject)
                        {
                            
                            SetJudgeObjectInfo(ref itemJob, ref listJudgeObject, childDataID);
                           
                        }
                        else if (
                            (itemJob.CateGoryID == (int)Category.InputObject) ||
                            (itemJob.CateGoryID == (int)Category.手書)  )
                        {
                            
                            SetInputObjectInfo(ref itemJob, ref listInputObject, childDataID);
                          

                        }
                        else if (itemJob.CateGoryID == (int)Category.非文字)
                        {
                            SetBlockObjectInfo(ref itemJob, ref listBlockObject, childDataID);
                        }
                        else if (itemJob.CateGoryID == (int)Category.FrameResult)
                        {
                            SetFormResultInfo(ref itemJob, ref listFramtResult, childDataID);
                        }


                    }
                    #endregion



                    //回写受番信息
                    SetOrderInfo(itemJob, ref    modelOrder);


                }

                #endregion

                #region 数据写入
 

                writeMsg("InsertDB @" + System.DateTime.Now.ToLongTimeString());

                //分解数据写入数据库
                SaveDecompositionData(
                    orderId,
                    StaticID,
                    modelOrder,
                    listModelParentData,
                    listFrameObject,
                    listBlockObject,
                    listJudgeObject,
                    listInputObject,
                    listJob,
                    listJobLog,
                    listFramtResult
                    );


                string endMsg = "Decomposite End  @" + System.DateTime.Now.ToLongTimeString() + "--" + orderId.ToString();
                Logic.Log.Info(endMsg);
                writeMsg(endMsg);
 
                #endregion

            }
            catch (Exception ex)
            {
                string exMessage = "Exception : ";
                exMessage += Environment.NewLine;
                exMessage += "orderID:"+ modelOrder.OrderID;
                exMessage += Environment.NewLine;
                exMessage += "ImageID:" + errorImageId;
                Log.Error(exMessage, ex);

                throw ex;
            }

        }

        #endregion

        #region 数据写入分解数据库

        private  void SaveDecompositionData( 
            Guid orderId,  
            Guid StaticID,
            DecompositionModel.ModelOrder modelOrder,
            List<DecompositionModel.ModelParentObject> listModelParentData,
            List<DecompositionModel.ModelFrameObject> listFrameObject,
            List<DecompositionModel.ModelBlockObject> listBlockObject,
            List<DecompositionModel.ModelJudgeObject> listJudgeObject,
            List<DecompositionModel.ModelInputObject> listInputObject,
            List<DecompositionModel.ModelJob> listJob,
            List<DecompositionModel.ModelJobLog> listJobLog,
            List<DecompositionModel.ModelFrameResult> listFrameResult

            )
        {

            DecompositionDB.DataProvider DecompositionDBProvider = new DecompositionDB.DataProvider();

            #region 数据写入分解数据库
            //--------------step 2  写入数据库
            OrderState orderState = OrderState.UnFinished;
            if (modelOrder.FinishDateTime != null)
            {
                orderState = OrderState.Finished;
            }
            
            #region 删除上次分解数据

            DropOrderDatas(orderId,ServerAddress);

            #endregion

            #region 写入开始标志

 
            string memo =  ServerAddress;//"server=192.168.163.41";

            DecompositionDBProvider.StaticInsert(
                orderId
                , orderState.ToString()
                , StaticID
                , DateTime.Now
                ,memo
                );

            #endregion

            #region 写入order

            //--------------Write Order
            DecompositionDBProvider.OrderInsert(
                  modelOrder.OrderID
                , modelOrder.MatterID
                , modelOrder.MatterName
                , modelOrder.DataCount
                , modelOrder.DeliverDate
                , modelOrder.OrderDeliverDateTime
                , modelOrder.StarDateTime
                , modelOrder.FinishDateTime
                , modelOrder.OrderDateTime
                , modelOrder.CreateTime
                 , modelOrder.MTDuration
                 , modelOrder.MTPropagationTime
                 , modelOrder.TrimerDuration
                 , modelOrder.TrimerPropagationTime
                 , modelOrder.OCRDuration
                 , modelOrder.OCRPropagationTime

                 , modelOrder.ΑDuration
                 , modelOrder.ΑPropagationTime
                 , modelOrder.ΒDuration
                 , modelOrder.ΒPropagationTime
                 , modelOrder.ADuration
                 , modelOrder.APropagationTime
                 , modelOrder.BDuration
                 , modelOrder.BPropagationTime
                 , modelOrder.DDuration
                 , modelOrder.DPropagationTime
                 , modelOrder.EDuration
                 , modelOrder.EPropagationTime
                 , modelOrder.JudgeJobCount
                 , modelOrder.ABJobCount
                 , modelOrder.DJobCount
                 , modelOrder.EJobCount
                 , StaticID
                 , modelOrder.MachineDistinguishDuration
                 , modelOrder.MachineDistinguishPropagationTime
                 , modelOrder.ManualDistinguishDuration
                 , modelOrder.ManualDistinguishPropagationTime
                 ,modelOrder.UserOrder
                 , modelOrder.AImageCount
                 , modelOrder.BImageCount
                 , modelOrder.DImageCount
                 , modelOrder.EImageCount
                 , modelOrder.TrimerJobCount
                 , modelOrder.TrimerImageCount
                 , modelOrder.JudegADuration
                 , modelOrder.JudegAPropagationTime
                 , modelOrder.JudegBDuration
                 , modelOrder.JudegBPropagationTime
                 , modelOrder.JudageAJobCount
                 , modelOrder.JudageBJobCount
                 , modelOrder.JudgeAImageCount
                 , modelOrder.JudgeBImageCount
                 , modelOrder.FJobCount
                 , modelOrder.FDuration
                 , modelOrder.FPropagationTime
                 , modelOrder.FImageCount
                 , modelOrder.GJobCount
                 , modelOrder.GDuration
                 , modelOrder.GPropagationTime
                 , modelOrder.GImageCount
                , modelOrder.OrderCancelDateTime
                , modelOrder.Orderproperty == null || modelOrder.Orderproperty.Comment ==null ? string.Empty : modelOrder.Orderproperty.Comment.ToString()
                , modelOrder.Orderproperty == null || modelOrder.Orderproperty.CustomerInformation == null ? string.Empty : modelOrder.Orderproperty.CustomerInformation.ToString()

                 );


            foreach (DecompositionModel.ModelProgress item in modelOrder.ListModelProgress)
                {

                    DecompositionDBProvider.ProgressResultInsert(
                        orderId,
                        modelOrder.OrderID,
                        null,
                        item.ArgFlow,
                        item.ArgStartDatetime,
                        item.ArgFinishedDatetime,
                        "Order",
                        StaticID);
                }

            foreach (DecompositionModel.ModelException item in modelOrder.GetListException())
                {
                    DecompositionDBProvider.ExceptionInsert(item.Detail,item.Exception);
                }

                

            #endregion

            #region 写入job

            //---------------Write job
                foreach (DecompositionModel.ModelJob item in listJob)
            {
                DecompositionDBProvider.JobInsert(
                      item.JobID
                    , item.OrderID
                    , item.JobClass.ToString()
                    , item.CateGoryID
                    , ((Category)item.CateGoryID).ToString()
                    , item.LoginName
                    , item.DownloadDateTime
                    , item.UploadDateTime
                    , item.Duration
                    , item.PropagationTime
                    , item.RecordedDataCount
                    , item.RecordedDuration 
                    , item.JobLoad
                    , item.WordCount
                    , item.CreateDateTime
                    , item.DataCount
                    , StaticID
                    , item.JobDuration
                    , item.FileSizeCount
                    , item.MProperty ==null?string.Empty: item.MProperty.ImageType
                    , item.MProperty == null ? string.Empty : item.MProperty.ScriptType
                    , item.MProperty == null ? string.Empty : item.MProperty.WordDirection
                    , item.MProperty == null ? string.Empty : item.MProperty.WordFlag
                    , item.MProperty == null ? string.Empty : item.MProperty.WordType

                    , item.MProperty == null ? string.Empty : item.MProperty.MatterType
                    , item.MProperty == null ?  0 : item.MProperty.Warning
                    , item.MProperty == null ? string.Empty : item.MProperty.IsConstraintEntry
                    );
              

                    //ABjob对应的是一条内容
                    //drop by lidawei 2011-1-6
                    //if ((item.JobClass != JobClassAll.β) && (item.JobClass != JobClassAll.B) )
                    //{
                        foreach (DecompositionModel.ModelProgress itemModelProgress in item.ListModelProgress)
                        {

                            DecompositionDBProvider.ProgressResultInsert(
                                orderId,
                                item.JobID,
                                item.JobClass.ToString(),
                                itemModelProgress.ArgFlow,
                                itemModelProgress.ArgStartDatetime,
                                itemModelProgress.ArgFinishedDatetime,
                                "Job",
                                StaticID);
                        }
                    //}
                    foreach (DecompositionModel.ModelException itemException in item.GetListException())
                    {
                        DecompositionDBProvider.ExceptionInsert(itemException.Detail, itemException.Exception);
                    }

            }

            #endregion

            #region 写入parent

            //----------------Write Parent
                foreach (DecompositionModel.ModelParentObject item in listModelParentData)
            {
                DecompositionDBProvider.ParentInsert(
                      item.ParentDataID 
                    , item.OrderID
                    , item.FrameCount
                    , item.FileName
                    , StaticID
                    );
            }

            #endregion

            #region 写入frame

            //----------------write Frame
            foreach (DecompositionModel.ModelFrameObject item in listFrameObject)
            {
                if ((item.MachineDistinguishObject == null) && (item.ManuelDistinguishObject == null))
                {
                    DecompositionDBProvider.FrameInsert(
                         item.FrameID
                        , item.Parentid
                        , item.OrderID
                        , item.CategoryID
                        , ((Category)item.CategoryID).ToString()
                        , item.MTJobID
                        , item.TrimerJobID
                        , item.MTDuration
                        , item.TrimerDuration
                        , item.MTInputDateTime
                        , item.TrimerInputDateTime
                        , item.MTBlockCount
                        , item.TrimerBlockCount
                        , item.X
                        , item.Y
                        , item.Width
                        , item.Height
                        , StaticID
                        , item.FileSize
                        , item.MProperty == null ? string.Empty: item.MProperty.WordFlag
                        , item.MProperty == null ? string.Empty : item.MProperty.WordType
                        , item.MProperty == null ? 0 : item.MProperty.Warning
                        , item.DataStoreID
                        );


                    foreach (DecompositionModel.ModelProgress itemModelProgress in item.ListModelProgress)
                    {

                        DecompositionDBProvider.ProgressResultInsert(
                            orderId,
                            item.FrameID,
                            null,
                            itemModelProgress.ArgFlow,
                            itemModelProgress.ArgStartDatetime,
                            itemModelProgress.ArgFinishedDatetime,
                            "Frame",
                            StaticID);
                    }
                }
                else
                {
                    if ( (item.MachineDistinguishObject != null) && (item.MachineDistinguishObject.JobID != null))
                    {
                         

                        DecompositionDBProvider.DistinguishObjectInsert(
                            item.FrameID, item.Parentid, item.OrderID
                            , item.CategoryID, ((Category)item.CategoryID).ToString()
                            , (Guid)item.MachineDistinguishObject.JobID, item.MachineDistinguishObject.JobClass
                            , item.MachineDistinguishObject.Duration, (DateTime)item.MachineDistinguishObject.InputDateTime
                            , item.MachineDistinguishObject.Transverse, item.MachineDistinguishObject.Result
                            , item.X, item.Y, item.Width, item.Height, StaticID,item.FileSize);
                     }

                    if ((item.ManuelDistinguishObject != null)&& (item.ManuelDistinguishObject.JobID != null))
                    {
                        DecompositionDBProvider.DistinguishObjectInsert(
                            item.FrameID, item.Parentid, item.OrderID
                            , item.CategoryID, ((Category)item.CategoryID).ToString()
                            , (Guid)item.ManuelDistinguishObject.JobID, item.ManuelDistinguishObject.JobClass
                            , item.ManuelDistinguishObject.Duration, (DateTime)item.ManuelDistinguishObject.InputDateTime
                            , item.ManuelDistinguishObject.Transverse, item.ManuelDistinguishObject.Result
                            , item.X, item.Y, item.Width, item.Height, StaticID,item.FileSize);
                    }
                }
            }

            #endregion

            #region 写入block

            //----------------write Block
                foreach (DecompositionModel.ModelBlockObject item in listBlockObject)
            {
                DecompositionDBProvider.BlockInsert(
                      item.BlockID
                    , item.Frameid
                    , item.OrderID
                    , item.JobID
                    , item.CategoryID
                    , ((Category)item.CategoryID).ToString()
                    , item.OcrInputDateTime
                    , item.OcrDuration

                    , item.MProperty == null? string.Empty: item .MProperty.WordDirection
                    , item.MProperty == null ? string.Empty : item.MProperty.WordFlag
                    , item.MProperty == null ? string.Empty : item.MProperty.WordType
                    , item.MProperty == null ? string.Empty : item.MProperty.WordDirection
                    , item.ManuscriptType
                    , item.X
                    , item.Y
                    , item.Width
                    , item.Height
                    , item.InputObjectCount
                    , StaticID
                    , item.FileSize
                    , item.MProperty == null ? string.Empty : item.MProperty.ImageType
                    , item.MProperty == null ? string.Empty : item.MProperty.MatterType
                  

                    );

                foreach (DecompositionModel.ModelProgress itemModelProgress in item.ListModelProgress)
                {

                    DecompositionDBProvider.ProgressResultInsert(
                        orderId,
                        item.BlockID,
                        null,
                        itemModelProgress.ArgFlow,
                        itemModelProgress.ArgStartDatetime,
                        itemModelProgress.ArgFinishedDatetime,
                        "Block",
                        StaticID);
                }

            }

            #endregion

            #region 写入Judge

            //----------------write JudgeObject
            foreach (DecompositionModel.ModelJudgeObject item in listJudgeObject)
            {


                foreach (DecompositionModel.ModelJudgeResult itemm in item.ListJudgeResult)
                { 
                    

                    DecompositionDBProvider.JudgeInsert(
                      item.JudgeID
                    , item.InputobjectID
                    , item.CategoryID
                    , ((Category)item.CategoryID).ToString()
                    , item.JobID
                    , item.OrderID
                    , itemm.JobClass.ToString()
                    , itemm.LoginName
                    , itemm.Duration
                    , itemm.InputTime
                    , item.Transverse
                    , itemm.WordCount
                    , itemm.ErrorCount
                    , item.Index
                    , item.X
                    , item.Y
                    , item.Width
                    , item.Height
                    , StaticID
                    , item.FileSize
                    );

                    //β的图片内容和α的一样
                    if (itemm.JobClass == JobClassAll.α)
                    {
                        foreach (DecompositionModel.ModelProgress itemModelProgress in item.ListModelProgress)
                        {

                            DecompositionDBProvider.ProgressResultInsert(
                                orderId,
                                item.JudgeID,
                                null,
                                itemModelProgress.ArgFlow,
                                itemModelProgress.ArgStartDatetime,
                                itemModelProgress.ArgFinishedDatetime,
                                "Judge",
                                StaticID);
                        }
                    }

                    for (int i = 0; i < itemm.CandidacyJudgeResult.Count; i++)
                    {
                        DecompositionModel.ModelCandidacyJudgeResult itemmm = itemm.CandidacyJudgeResult[i];
              
                        if (itemmm != null)
                        {
                            int iCount = itemmm.ListCandidacyJudgeResult.Count;
                            string[] result ={string.Empty,string.Empty,string.Empty,string.Empty,string.Empty};
                            for (int ii = 0; ii < iCount; ii++)
                            {
                                result[ii] = itemmm.ListCandidacyJudgeResult[ii].ToString();
                            }
                            
                            DecompositionDBProvider.JudgeResultInsert(
                                  itemm.JudgeID
                                , item.OrderID
                                , result[0].ToString()
                                , result[1].ToString()
                                , result[2].ToString()
                                , result[3].ToString()
                                , result[4].ToString()                                
                                , itemmm.Result                                
                                , itemm.LoginName
                                , itemm.JobClass.ToString()    
                                , StaticID 
                                    ,i
                                ,itemmm.IsNullResult.ToString ()
                                );
                        }
                    }
                   
                    //
  

                }

                //增加FinalResult
                   for (int i = 0; i < item.FinalResult.Count; i++)
                    {
                        DecompositionModel.ModelCandidacyJudgeResult finalResult = item.FinalResult[i];

                        if (finalResult != null)
                        {
                            int iCount = finalResult.ListCandidacyJudgeResult.Count;
                            string[] result = { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty };
                            for (int ii = 0; ii < iCount; ii++)
                            {
                                result[ii] = finalResult.ListCandidacyJudgeResult[ii].ToString();
                            }

                            DecompositionDBProvider.JudgeResultInsert(
                                 item.JudgeID                             
                                , item.OrderID
                                , result[0].ToString()
                                , result[1].ToString()
                                , result[2].ToString()
                                , result[3].ToString()
                                , result[4].ToString()
                                , finalResult.Result
                                , string.Empty
                                , "FinalResult"
                                , StaticID
                                    , i
                                , finalResult.IsNullResult.ToString()
                                );
                        }
                    }
            }

            #endregion

            #region 写入input

            //--------------------write InputObject
            foreach (DecompositionModel.ModelInputObject item in listInputObject)
            {
                
                try
                {
                    //if (item.AEntry != null && item.AEntry.EntryWords != null)
                    //{
                    //    string abc = item.AEntry.EntryWords;
                    //}
                    //if (item.BEntry != null && item.BEntry.EntryWords != null)
                    //{
                    //    string bcd = item.BEntry.EntryWords;
                    //}


                    DecompositionDBProvider.InputObjectInsert(
                        item.InputId
                        , item.BlockId
                        , item.FrameId
                        , item.OrderID
                        , item.CategoryID
                        , ((Category)item.CategoryID).ToString()
                        //item.WorldCounts 
                        //2010 3 11 按照E结果的文字数来确定wordCount
                        , item.EEntry == null? 0:item.EEntry.Result.Length 
                        , item.αEntry == null ? 0 : item.αEntry.Duration
                        , item.βEntry == null ? 0 : item.βEntry.Duration
                        , item.αβAttachWordsResult == null ? string.Empty : item.αβAttachWordsResult
                        , item.αβAttachFlag.ToString()
                        , item.JudgeErrorCount
                         , item.AEntry == null ? string.Empty : item.AEntry.Result
                        , item.AEntry == null ? string.Empty : item.AEntry.Comment
                        , item.AEntry == null ? 0 : item.AEntry.Duration
                        , item.AEntry == null ? new Guid() : item.AEntry.JobID
                        , item.AEntry == null ? string.Empty : item.AEntry.LoginName

                        , item.BEntry == null ? string.Empty : item.BEntry.Result
                        , item.BEntry == null ? string.Empty : item.BEntry.Comment
                        , item.BEntry == null ? 0 : item.BEntry.Duration
                        , item.BEntry == null ? new Guid() : item.BEntry.JobID
                        , item.BEntry == null ? string.Empty : item.BEntry.LoginName

                        , item.DEntry == null ? string.Empty : item.DEntry.Result
                        , item.DEntry == null ? string.Empty : item.DEntry.Comment
                        , item.DEntry == null ? 0 : item.DEntry.Duration
                        , item.DEntry == null ? new Guid() : item.DEntry.JobID
                        , item.DEntry == null ? string.Empty : item.DEntry.LoginName

                        , item.EEntry == null ? string.Empty : item.EEntry.Result
                        , item.EEntry == null ? string.Empty : item.EEntry.Comment
                        , item.EEntry == null ? 0 : item.EEntry.Duration
                        , item.EEntry == null ? new Guid() : item.EEntry.JobID
                        , item.EEntry == null ? string.Empty : item.EEntry.LoginName

                        , item.FinalEntry == null ? string.Empty : item.FinalEntry.Result
                        , item.FinalEntry == null ? string.Empty : item.FinalEntry.Comment
                        , item.Index
                        , item.X
                        , item.Y
                        , item.Width
                        , item.Height
                        , item.MProperty == null ? string.Empty : item.MProperty.WordDirection

                        , item.MProperty == null ? string.Empty : item.MProperty.WordDirection
                        , item.MProperty == null ? string.Empty : item.MProperty.ScriptType
                        , item.MProperty == null ? string.Empty : item.MProperty.WordType

                        , StaticID

                        , item.AEntry != null && item.AEntry.EntryWords != null ? item.AEntry.EntryWords : string.Empty
                        , item.BEntry != null && item.BEntry.EntryWords != null ? item.BEntry.EntryWords : string.Empty
                        , item.FileSize
                        , item.MProperty == null? string.Empty : item.MProperty.ImageType
                        , item.MProperty == null ? string.Empty : item.MProperty.MatterType

                        , item.OcrEntry == null ? string.Empty : item.OcrEntry.Result                         
                        , item.JudgeAEntry == null? string.Empty:item.JudgeAEntry.Result
                        , item.JudgeAEntry == null? 0:item.JudgeAEntry.Duration
                        , item.JudgeAEntry == null? new Guid() : item.JudgeAEntry.JobID
                        , item.JudgeAEntry == null? string.Empty:item.JudgeAEntry.LoginName
 
                        , item.JudgeBEntry == null? string.Empty:item.JudgeBEntry.Result
                        , item.JudgeBEntry == null? 0:item.JudgeBEntry.Duration
                        , item.JudgeBEntry == null? string.Empty:item.JudgeBEntry.LoginName

                        , item.MProperty == null ? 0: item.MProperty.Warning
                        , item.DataStoreID == null ? new Guid() : item.DataStoreID
                        , item.FinalEntry == null?string.Empty:item.FinalEntry.SplitResult
                        );

                    foreach (DecompositionModel.ModelProgress itemModelProgress in item.ListModelProgress)
                    {

                        DecompositionDBProvider.ProgressResultInsert(
                            orderId,
                            item.InputId,
                            null,
                            itemModelProgress.ArgFlow,
                            itemModelProgress.ArgStartDatetime,
                            itemModelProgress.ArgFinishedDatetime,
                            "Input",
                            StaticID);
                    }

                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            #endregion

            #region FrameResult

            //----------------write FrameResult
            foreach (DecompositionModel.ModelFrameResult item in listFrameResult)
            {
                if (item.FrameResultID != null)
                {
                    //Write master record
                    DecompositionDBProvider.FrameResultMasterInsert(
                         item.FrameResultID
                        , item.Parentid
                        , item.OrderID
                        , item.CategoryID
                        ,  ((Category)item.CategoryID).ToString() 
                        
                        //, item.Property.WordFlag
                        //, item.Property.WordDirection
                        //, item.Property.ScriptType
                        //, item.Property.WordType
                        //, item.Property.ImageType
                        //, item.Property.MatterType
                        //, item.Property.Warning
                        //, item.Property.UserOrder
                        //, item.Property.IsConstraintEntry

                        , item.BlockCount
                        , item.FJobID
                        , item.GJobID
                        , item.FLoginName
                        , item.GLoginName
                        , item.FDuration
                        , item.GDuration
                        , item.FInputDateTime
                        , item.GInputDateTime
                        , item.FComment
                        , item.GComment
                        , item.X
                        , item.Y
                        , item.Width
                        , item.Height
                        , StaticID
                        , item.FileSize
                        );

                    //write progress record
                    if (item.ListModelProgress != null)
                    {
                        foreach (DecompositionModel.ModelProgress itemModelProgress in item.ListModelProgress)
                        {

                            DecompositionDBProvider.ProgressResultInsert(
                                orderId,
                                item.FrameResultID,
                                null,
                                itemModelProgress.ArgFlow,
                                itemModelProgress.ArgStartDatetime,
                                itemModelProgress.ArgFinishedDatetime,
                                "FramResult",
                                StaticID);
                        }
                    }

                    //Write Detail record
                    if ((item.resultItem != null) && (item.resultItem.Count > 0))
                    {
                        foreach (DecompositionModel.ModelFrameResult.ModelFrameDetailReuslt detailReuslt in item.resultItem)
                        {
                            Guid jobID = new Guid();

                            if (detailReuslt.JobClass == JobClassAll.F)
                                jobID = item.FJobID;
                            else if (detailReuslt.JobClass == JobClassAll.G)
                                jobID = item.GJobID;

                            DecompositionDBProvider.FrameResultDetailInsert(
                              item.OrderID,
                              item.FrameResultID,
                              jobID,
                              detailReuslt.JobClass.ToString(),
                                ((Orid.Management.Common.Job.BusinessCardProperty)detailReuslt.ImageType).ToString(),
                              detailReuslt.Rect.X,
                              detailReuslt.Rect.Y,
                              detailReuslt.Rect.Width,
                              detailReuslt.Rect.Height,
                              detailReuslt.Result,
                              detailReuslt.IsChange,
                              StaticID);
                        }

                    }


                }
            }

            #endregion FrameResult

            #region write joblogs

            foreach (DecompositionModel.ModelJobLog item in listJobLog)
            {

                DecompositionDBProvider.CancelJobLogsInsert(
                            item.JobID,
                            item.OrderID,
                            item.LoginName,
                            item.CancelDatetime,
                            StaticID);
            }
            #endregion

            #region 写入结束标志

            DecompositionDBProvider.StaticUpdate(StaticID, DateTime.Now);

            #endregion

            #endregion

        }

        /// <summary>
        /// Drops the order datas.
        /// </summary>
        /// <param name="orderId">The order id.</param>
        /// <param name="serverAddress">The server address.</param>
        private void DropOrderDatas(Guid orderId, string serverAddress)
        {
            #region 删除上次分解数据

            bool dropflag;

           if (string.IsNullOrEmpty(Config.Setting.SettingInstance.DropOrderFlag ) )
           {
               dropflag = false;
           }

            try
            {
                dropflag = Convert.ToBoolean(Config.Setting.SettingInstance.DropOrderFlag);
               
            }
            catch
            {
                dropflag = false;
                   
            }

            if (!dropflag )
                return;

            DecompositionDB.DataProvider DecompositionDBProvider = new DecompositionDB.DataProvider();
            writeMsg("DeletDB Star @" + System.DateTime.Now.ToLongTimeString());

#if  SingleMA 
            DecompositionDBProvider.OrderDelete(orderId);
            DecompositionDBProvider.JobDelete(orderId);
            DecompositionDBProvider.ParentDelete(orderId);
            DecompositionDBProvider.FrameDelete(orderId);
            DecompositionDBProvider.BlockDelete(orderId);
            DecompositionDBProvider.InputDelete(orderId);
            DecompositionDBProvider.JudgeDelete(orderId);
            DecompositionDBProvider.JudgeResultDelete(orderId);
            //20100415 add lidawei            
            DecompositionDBProvider.ProgressResultDelete(orderId);
            DecompositionDBProvider.DistinguishObjectDelete(orderId);
            DecompositionDBProvider.CancelJobLogsDelete(orderId);
             //20101221 add
            DecompositionDBProvider.FrameResultDelete(orderId);
#else
         
            DecompositionDBProvider.OrderDelete(orderId, serverAddress);
            DecompositionDBProvider.JobDelete(orderId, serverAddress);
            DecompositionDBProvider.ParentDelete(orderId, serverAddress);
            DecompositionDBProvider.FrameDelete(orderId, serverAddress);
            DecompositionDBProvider.BlockDelete(orderId, serverAddress);
            DecompositionDBProvider.InputDelete(orderId, serverAddress);
            DecompositionDBProvider.JudgeDelete(orderId, serverAddress);
            DecompositionDBProvider.JudgeResultDelete(orderId, serverAddress);
            //20100415 add lidawei            
            DecompositionDBProvider.ProgressResultDelete(orderId, serverAddress);
            DecompositionDBProvider.DistinguishObjectDelete(orderId, serverAddress);
            DecompositionDBProvider.CancelJobLogsDelete(orderId, serverAddress);

            //20101221 add
            DecompositionDBProvider.FrameResultDelete(orderId, serverAddress);

#endif

            writeMsg("DeletDB End @" + System.DateTime.Now.ToLongTimeString());

            #endregion
        }

        #endregion

        #region 判断付签是否是未记载

        /// <summary>
        /// 未记载 == true ?
        /// </summary>
        /// <param name="comment"></param>
        /// <returns></returns>
        private bool CommentIsNoMention(string comment)
        {
            bool flag = false;

            if (comment == null)
            {
                return false;
            }

            if  (comment .Equals(  CommentTypes.None.ToString()))
            {
                flag=true;
            }

            return flag;
        }
        #endregion

        #region 私有方法计算过程中用到

        /// <summary>
        /// MT  Trimer 结果
        /// </summary>
        /// <param name="modelJob"></param>
        /// <param name="listFrameObject"></param>
        /// <param name="childDataID"></param>
        private void SetFormObjectInfo(ref DecompositionModel.ModelJob modelJob, ref  List<DecompositionModel.ModelFrameObject> listFrameObject, Guid childDataID)
        {
            foreach (DecompositionModel.ModelFrameObject itemFrameObject in listFrameObject)
            {
                if (itemFrameObject.FrameID.Equals(childDataID))
                {
                    
                    
                    if (modelJob.JobClass == JobClassAll.MT)
                    {
                        itemFrameObject.MTJobID = modelJob.JobID;
                        modelJob.Duration += itemFrameObject.MTDuration;
                        //2010 05 06 追加 lidawei 
                        modelJob.WordCount += itemFrameObject.MTBlockCount;

                        //2010 05 13 Add lidawei
                        modelJob.FileSizeCount += itemFrameObject.FileSize;
                       
                    }
                    else if (modelJob.JobClass == JobClassAll.Trimer)
                    {
                        itemFrameObject.TrimerJobID = modelJob.JobID;
                        modelJob.Duration += itemFrameObject.TrimerDuration;
                        //2010 05 06 追加 lidawei 
                        modelJob.WordCount += itemFrameObject.TrimerBlockCount;

                        //2010 05 13 Add lidawei
                        modelJob.FileSizeCount += itemFrameObject.FileSize;

                      
                    }
                    else if (modelJob.JobClass == JobClassAll.機械仕分)
                    {
                        if (itemFrameObject.MachineDistinguishObject != null)
                        {
                            itemFrameObject.MachineDistinguishObject.JobID = modelJob.JobID;
                            modelJob.Duration += itemFrameObject.MachineDistinguishObject.Duration;

                            //2010 05 13 Add lidawei
                            modelJob.FileSizeCount += itemFrameObject.FileSize;
                        }
                    }
                    else if (modelJob.JobClass == JobClassAll.手動仕分)
                    {
                        if (itemFrameObject.ManuelDistinguishObject != null)
                        {
                            itemFrameObject.ManuelDistinguishObject.JobID = modelJob.JobID;
                            modelJob.Duration += itemFrameObject.ManuelDistinguishObject.Duration;

                            //2010 05 13 Add lidawei
                            modelJob.FileSizeCount += itemFrameObject.FileSize;
                        }
                    }

                }
            }
        }

        /// <summary>
        /// ocr结果
        /// </summary>
        /// <param name="modelJob"></param>
        /// <param name="listBlockObject"></param>
        /// <param name="childDataID"></param>
        private void SetBlockObjectInfo(ref DecompositionModel.ModelJob modelJob, ref  List<DecompositionModel.ModelBlockObject> listBlockObject, Guid childDataID)
        {
            foreach (DecompositionModel.ModelBlockObject itemBlockObject in listBlockObject)
            {
                if (itemBlockObject.BlockID == childDataID)
                {  
                   
                  //itemBlockObject.JobID = modelJob.JobID;

                    //ocr
                    if (modelJob.JobClass == JobClassAll.OCR)
                    {
                        itemBlockObject.JobID = modelJob.JobID;

                        modelJob.Duration += itemBlockObject.OcrDuration;

                        //2010 05 13 Add lidawei
                        modelJob.FileSizeCount += itemBlockObject.FileSize;
                    

                        //判断是否未记载
                        if (!CommentIsNoMention(itemBlockObject.OCRComment))
                        {
                            modelJob.RecordedDataCount += 1;
                            //   //ma release 25 drop
                          //  modelJob.RecordedPropagationTime += itemBlockObject.OcrPropagationTime;
                            modelJob.RecordedDuration += itemBlockObject.OcrDuration;                            
                        }
                    }
                    ////2011-1-24 lidawei add judage job
                    //else if (modelJob.JobClass == JobClassAll.判定)
                    //{
                        
                    //    //2010 05 13 Add lidawei
                    //    modelJob.FileSizeCount += itemBlockObject.FileSize;

                    //    //如果ocr识别出结果  RecordedDataCount + 1
                    //    if (!string.IsNullOrEmpty(itemBlockObject.OCRResult))
                    //    {
                    //        modelJob.RecordedDataCount += 1;
                    //    }
                    //}
                }
            }
        }

        /// <summary>
        /// 候補結果
        /// </summary>
        /// <param name="modelJob"></param>
        /// <param name="listJudgeObject"></param>
        /// <param name="childDataID"></param>
        private void SetJudgeObjectInfo(
            ref DecompositionModel.ModelJob modelJob,
            ref  List<DecompositionModel.ModelJudgeObject> listJudgeObject,
            Guid childDataID)
        {            
             // (childDataID ==  '68EB0F34-9943-4ED9-A13D-D95C7975B151')    


            foreach (DecompositionModel.ModelJudgeObject itemJudgeObject in listJudgeObject)
            {
               
                
                if (itemJudgeObject.JudgeID == childDataID)
                {
                     itemJudgeObject.JobID = modelJob.JobID;


                     if (modelJob.JobClassID == (int)JobClass.候補結果判定ジョブ)
                     {


                         //2010 05 13 Add lidawei
                         modelJob.FileSizeCount += itemJudgeObject.FileSize;

                         foreach (DecompositionModel.ModelJudgeResult itemModelJudgeResult in itemJudgeObject.ListJudgeResult)
                         { 
                             
                             if (itemModelJudgeResult.LoginName == modelJob.LoginName)
                             {
                                 itemModelJudgeResult.JobClass = modelJob.JobClass;
                                 modelJob.JobClass = itemModelJudgeResult.JobClass;
                                 modelJob.Duration += itemModelJudgeResult.Duration;
                                 //job文字数以判断中文字数为准
                                 modelJob.WordCount += itemModelJudgeResult.WordCount;

                                 //判断是否未记载
                                 if (!CommentIsNoMention(itemModelJudgeResult.Comment))
                                 {
                                     modelJob.RecordedDataCount += 1;
                                     //2010-09-18
                                     //lidawei
                                     //ma release 25 drop
                                     //modelJob.RecordedPropagationTime += itemModelJudgeResult.PropagationTime;
                                     modelJob.RecordedDuration += itemModelJudgeResult.Duration;
                                 }


                                 
                             }
 
                           

                         }
                    
                     }
  
                   
                    
                }

                
            }
        }

        /// <summary>
        /// A B C D  E job
        /// </summary>
        /// <param name="modelJob"></param>
        /// <param name="listInputObject"></param>
        /// <param name="childDataID"></param>
        private void SetInputObjectInfo(
            ref DecompositionModel.ModelJob modelJob,
            ref  List<DecompositionModel.ModelInputObject> listInputObject, 
            Guid childDataID)
        {
            foreach (DecompositionModel.ModelInputObject itemModelInputObject in listInputObject)
            {
                 int ocrWords = 0;

                if (itemModelInputObject.InputId == childDataID)
                {

                    DecompositionModel.ModelEntryObject entryObject = new DecompositionModel.ModelEntryObject();                 

                    //

                    #region 旧代码
                    ////如果AB的位置错误，根据Job中的结果为准, 调整结果顺序
                    //if ((modelJob.JobClass == JobClassAll.A) || (modelJob.JobClass == JobClassAll.B))
                    //{
                    //    if ((itemModelInputObject.AEntry != null) && (itemModelInputObject.BEntry != null))
                    //    {

                    //        if (
                    //            ((modelJob.LoginName == itemModelInputObject.AEntry.LoginName)
                    //            &&
                    //            (modelJob.JobClass == JobClassAll.B)
                    //            ) || (
                    //            (modelJob.LoginName == itemModelInputObject.BEntry.LoginName)
                    //            &&
                    //            (modelJob.JobClass == JobClassAll.A))
                    //            )
                    //        {
                    //            ModelEntryObject temp = itemModelInputObject.AEntry;
                    //            itemModelInputObject.AEntry = itemModelInputObject.BEntry;
                    //            itemModelInputObject.BEntry = temp;

                               
                    //        }
                    //    }

                    //}
                    ////ABジョブ
                    //if (modelJob.JobClass == JobClassAll.A)
                    //{
                    //    //AJob                    

                    //    entryObject = itemModelInputObject.AEntry;

                    //}
                    //else if ((modelJob.JobClass == JobClassAll.B))
                    //{ //Bjob
                    //    entryObject = itemModelInputObject.BEntry;
                    //}
                    //else if ((modelJob.JobClass == JobClassAll.C) || (modelJob.JobClass == JobClassAll.D))
                    //{
                    //    entryObject = itemModelInputObject.DEntry;
                    //}
                    //else if (modelJob.JobClass == JobClassAll.E)
                    //{
                    //    entryObject = itemModelInputObject.EEntry;
                    //}

                    #endregion

                    if (modelJob.JobClass == JobClassAll.A) 
                    {
                        foreach (DecompositionModel.ModelEntryObject item in itemModelInputObject.ABEntryList)
                        {
                            if (item.LoginName == modelJob.LoginName)
                            {
                                itemModelInputObject.AEntry = item;
                                entryObject = item;
                                break;
                            }
                        }
                

                    }
                    else if (modelJob.JobClass == JobClassAll.B) 
                    {
                        foreach (DecompositionModel.ModelEntryObject item in itemModelInputObject.ABEntryList)
                        {
                            if (item.LoginName == modelJob.LoginName)
                            {
                                itemModelInputObject.BEntry = item;
                                entryObject = item;
                                break;
                            }
                        }
            
                    }
                    else if ((modelJob.JobClass == JobClassAll.C) || (modelJob.JobClass == JobClassAll.D))
                    {
                        foreach (DecompositionModel.ModelEntryObject item in itemModelInputObject.DEntryList)
                        {
                         
                            if (item.LoginName == modelJob.LoginName)
                            {
                                itemModelInputObject.DEntry = item;
                                entryObject = item;
                                break;
                           }
                        }

                      

                    }
                    else if  (modelJob.JobClass == JobClassAll.E) 
                    {
                        foreach (DecompositionModel.ModelEntryObject item in itemModelInputObject.EEntryList)
                        {
                           
                            if (item.LoginName == modelJob.LoginName)
                            {
                                itemModelInputObject.EEntry = item;
                                entryObject = item;
                                break;
                            }
                        }
                      
                    }
                    if (modelJob.JobClass == JobClassAll.判定A)
                    {
                        foreach (DecompositionModel.ModelEntryObject item in itemModelInputObject.JudgeEntryList)
                        {
                            if (item.LoginName == modelJob.LoginName)
                            {
                                itemModelInputObject.JudgeAEntry = item;
                                entryObject = item;

                                ocrWords = itemModelInputObject.OcrEntry.Result.Length;
                                break;
                            }
                        }
                    }
                    if (modelJob.JobClass == JobClassAll.判定B)
                    {
                        foreach (DecompositionModel.ModelEntryObject item in itemModelInputObject.JudgeEntryList)
                        {
                            if (item.LoginName == modelJob.LoginName)
                            {
                                itemModelInputObject.JudgeBEntry = item;
                                entryObject = item;

                                ocrWords = itemModelInputObject.OcrEntry.Result.Length;
                                break;
                            }
                        }
                    }

                 

                    if (entryObject != null)
                    {
                        

                        entryObject.JobID = modelJob.JobID; 
                        modelJob.Duration += entryObject.Duration;
                        //job文字数以录入结果中文字数为准

                        //2010 05 13 Add lidawei
                        modelJob.FileSizeCount += itemModelInputObject.FileSize;


                        //2010 05 06 统计室依赖 追加
                        //活字  Printing
                        //手书  Handwriting
                        //2011-3-7 修改 无论手书活字 都用一个AB录入结果文字数来统计（无候补判定job流程）
                        if ((modelJob.JobClass == JobClassAll.A) || (modelJob.JobClass == JobClassAll.B))
                        {
                           //Ref #3605
                           //2011-3-7 修改
                           //由于已经没有候补判定Job
                           //所有AB 录入文字数的统计方法 
                           //无论活字还是手书 用的都是AB录入的文字数
                           /*
                            if (itemModelInputObject.ScriptType.ToLower() == "printing")
                            {
                                modelJob.WordCount += entryObject.EntryWords == null ? 0 : entryObject.EntryWords.Length;
                            }
                            else
                            {

                                modelJob.WordCount += entryObject.Result == null ? 0 : entryObject.Result.Length;
                            }
                            */

                            modelJob.WordCount += entryObject.Result == null ? 0 : entryObject.Result.Length;
                        }
                        else if (modelJob.JobClass == JobClassAll.判定A || modelJob.JobClass == JobClassAll.判定B)
                        {
                            //2010-2-17 modify 
                            //判断job中字数不对
                            modelJob.WordCount += ocrWords;
                        }
                        else
                        {
                             modelJob.WordCount += entryObject.Result == null ? 0 : entryObject.Result.Length;
                        }


                        //判断是否未记载
                        if (!CommentIsNoMention(entryObject.Comment))
                        {
                            modelJob.RecordedDataCount += 1;
                            //2010-09-18
                            //lidawei
                            //ma release 25 drop
                            //modelJob.RecordedPropagationTime += entryObject.PropagationTime;
                            modelJob.RecordedDuration += entryObject.Duration;
                        }
                    }
                }




            }

        }

        private void SetOrderInfo(
            DecompositionModel.ModelJob modelJob,
            ref  DecompositionModel.ModelOrder modelOrder)
        { 
            //2010-2-25 add
            if (modelJob.JobClass == JobClassAll.判定A)
            {
                modelOrder.JudegADuration += modelJob.Duration;
                modelOrder.JudegAPropagationTime += modelJob.PropagationTime;

               
                modelOrder.JudageAJobCount ++;
                modelOrder.JudgeAImageCount += modelJob.DataCount;
            }
                //2010-2-25 add
            else if (modelJob.JobClass == JobClassAll.判定B)
            {
                modelOrder.JudegBDuration += modelJob.Duration;
                modelOrder.JudegBPropagationTime += modelJob.PropagationTime;

              
                modelOrder.JudageBJobCount++;
                modelOrder.JudgeBImageCount += modelJob.DataCount;
            }
            else if (modelJob.JobClass == JobClassAll.MT)
            {
                modelOrder.MTDuration += modelJob.Duration;
                modelOrder.MTPropagationTime += modelJob.PropagationTime;
             
            }
            else if (modelJob.JobClass == JobClassAll.Trimer)
            {
                modelOrder.TrimerDuration += modelJob.Duration;
                modelOrder.TrimerPropagationTime += modelJob.PropagationTime;

                //2010-2-25 add
                modelOrder.TrimerJobCount++;
                modelOrder.TrimerImageCount += modelJob.DataCount;
            }
            else if (modelJob.JobClass == JobClassAll.OCR)
            {
                modelOrder.OCRDuration += modelJob.Duration;
                modelOrder.OCRPropagationTime += modelJob.PropagationTime;
            }
            else if (modelJob.JobClass == JobClassAll.α)
            {
                modelOrder.ΑDuration += modelJob.Duration;
                modelOrder.ΑPropagationTime += modelJob.PropagationTime;
                modelOrder.JudgeJobCount++;
            }
            else if (modelJob.JobClass == JobClassAll.β)
            {
                modelOrder.ΒDuration += modelJob.Duration;
                modelOrder.ΒPropagationTime += modelJob.PropagationTime;
                modelOrder.JudgeJobCount++;
              
            }
            else if (modelJob.JobClass == JobClassAll.A)
            {
                modelOrder.ADuration += modelJob.Duration;
                modelOrder.APropagationTime += modelJob.PropagationTime;
                modelOrder.ABJobCount++;

                modelOrder.AImageCount += modelJob.DataCount;
            }
            else if (modelJob.JobClass == JobClassAll.B)
            {
                modelOrder.BDuration += modelJob.Duration;
                modelOrder.BPropagationTime += modelJob.PropagationTime;
                modelOrder.ABJobCount++;

                modelOrder.BImageCount += modelJob.DataCount;

            }
            else if (modelJob.JobClass == JobClassAll.D)
            {
                modelOrder.DDuration += modelJob.Duration;
                modelOrder.DPropagationTime += modelJob.PropagationTime;
                modelOrder.DJobCount ++;

                modelOrder.DImageCount += modelJob.DataCount;

            }
            else if (modelJob.JobClass == JobClassAll.E)
            {
                modelOrder.EDuration += modelJob.Duration;
                modelOrder.EPropagationTime += modelJob.PropagationTime;
                modelOrder.EJobCount ++;

                modelOrder.EImageCount += modelJob.DataCount;

            }
            else if (modelJob.JobClass == JobClassAll.機械仕分)
            {
                modelOrder.MachineDistinguishPropagationTime += modelJob.PropagationTime;
                modelOrder.MachineDistinguishDuration += modelJob.Duration;
            }
            else if (modelJob.JobClass == JobClassAll.手動仕分)
            {
                modelOrder.ManualDistinguishPropagationTime += modelJob.PropagationTime;
                modelOrder.ManualDistinguishDuration += modelJob.Duration;
            }
            else if (modelJob.JobClass == JobClassAll.F)
            {
                modelOrder.FDuration += modelJob.Duration;
                modelOrder.FPropagationTime += modelJob.PropagationTime;

                modelOrder.FJobCount++;
                modelOrder.FImageCount += modelJob.DataCount;
            }
            else if (modelJob.JobClass == JobClassAll.G)
            {
                modelOrder.GDuration += modelJob.Duration;
                modelOrder.GPropagationTime += modelJob.PropagationTime;

                modelOrder.GJobCount++;
                modelOrder.GImageCount += modelJob.DataCount;
            }
        }

        private void SetFormResultInfo(ref DecompositionModel.ModelJob modelJob, ref  List<DecompositionModel.ModelFrameResult> listFrameResult, Guid childDataID)
        {
            foreach (DecompositionModel.ModelFrameResult itemFrameResult in listFrameResult)
            {
                if (itemFrameResult.FrameResultID.Equals(childDataID) && itemFrameResult.JobClass != JobClassAll.Final) 
                {

                    if  (modelJob.JobClass == JobClassAll.F) 
                    {
                        itemFrameResult.FJobID = modelJob.JobID;
                        modelJob.Duration += itemFrameResult.FDuration;
                       
                        modelJob.WordCount += itemFrameResult.BlockCount;
                        
                        modelJob.FileSizeCount += itemFrameResult.FileSize;

                    }
                    else if (modelJob.JobClass == JobClassAll.G)
                    {
                        itemFrameResult.GJobID = modelJob.JobID;
                        modelJob.Duration += itemFrameResult.GDuration;

                        if ( modelJob.WordCount ==0 )
                            modelJob.WordCount = itemFrameResult.BlockCount;

                        if (modelJob.FileSizeCount == 0)
                            modelJob.FileSizeCount += itemFrameResult.FileSize;
                    }

                }
            }

 

        }

        private void FillJobItem(
            ref DecompositionModel.ModelJob modelJob,
            DecompositionData .Job job)
        {
            DecompositionModel.ModelJob model = job.GetJob(modelJob.JobID);

            //if (model.JobID.ToString().ToUpper() == "F58C24B2-06C3-47FE-83FC-765066185A38")
            //{
            //    string a = "";
            //}

            modelJob.AllowDownloadTimes = model.AllowDownloadTimes;
            modelJob.CateGoryID = model.CateGoryID;
            modelJob.ChildImage =  model.ChildImage;
            modelJob.CreateDateTime = model.CreateDateTime;
            modelJob.DataCount =  model.DataCount;
            modelJob.Duration = model.Duration;

            modelJob.JobClass = GetJobClass(
                modelJob.CateGoryID, modelJob.JobClassID, modelJob.DownLoadID
                );

            modelJob.JobLoad = model.JobLoad;
            modelJob.TakeDateTime =  model.TakeDateTime;
            //2010-4-14 修改  本番数据库中job表中的worldCount不使用
            modelJob.WordCount = 0;// modelEntryResult.WordCount;
            //2010-04-15修改
            modelJob.ListModelProgress = model.ListModelProgress;

            /*
            //2010-06-02 追加 job语言属性
            modelJob.WordDirection = model.WordDirection;
            modelJob.WordFlag = model.WordFlag;
            modelJob.WordType = model.WordType;
            modelJob.ScriptType = model.ScriptType;
            modelJob.ImageType = model.ImageType;

            //2010-07-27
            //MaRelease21版追加 对应
            modelJob.MatterType = model.MatterType;
            modelJob.Warning = model.Warning;
            //2010-12-22 
            //marelease29 Add
            modelJob.IsConstraintEntry = model.IsConstraintEntry;
            modelJob.UserOrder = model.UserOrder;
             */

            modelJob.MProperty = model.MProperty;
        }

        private JobClassAll GetJobClass(int CategoryID, int JobClassID, int DownloadID)
        {
            /*jobID
             * 1	判定ジョブ
                2	ABジョブ
                3	CDジョブ
                4	Eジョブ
                6	MTジョブ
                7	Trimerジョブ
                8	OCRジョブ
                9	候補結果判定ジョブ
                10	新ABジョブ
                11	新Dジョブ
                12	新Eジョブ
                14	EntryFinalジョブ
             * 
             * categoryid
             * 0	非文字
                2	手書
                10	Frame Object
                11	Block Object
                12	Judge Object
                13	Input Object
            */
            JobClassAll JobClass =JobClassAll.unKnow;
            if (CategoryID == 2)
            {
                if ((JobClassID == 2)) //ABジョブ 
                {
                    if (DownloadID == 0)
                    {
                        JobClass = JobClassAll.A;
                    }
                    else if (DownloadID == 1)
                    {
                        JobClass = JobClassAll.B;
                    }
                }
                else if ((JobClassID == 3))
                {
                    JobClass = JobClassAll.D;
                }
                else if ((JobClassID == 4))
                {
                    JobClass = JobClassAll.E;
                }
            }
            else if (CategoryID == 10 ||  CategoryID == 15)
            {
                // JobClass = "Frame";
                if (JobClassID == 6)
                {
                    JobClass = JobClassAll.MT;
                }
                else if (JobClassID == 7)
                {
                    JobClass = JobClassAll.Trimer;
                }
                else if (JobClassID == 14)
                {
                    JobClass = JobClassAll.Final;
                }
                else if (JobClassID == 15)
                {
                    JobClass = JobClassAll.機械仕分;
                }
                else if (JobClassID == 13)
                {
                    JobClass = JobClassAll.手動仕分;
                }


            }
            else if (CategoryID == 11)
            {
                if (JobClassID == 8)
                {
                    JobClass = JobClassAll.OCR;
                }
                else if (JobClassID == 1)
                {
                    if (DownloadID == 0)
                    {
                        JobClass = JobClassAll.判定A;
                    }
                    else if (DownloadID == 1)
                    {
                        JobClass = JobClassAll.判定B;
                    }
 
                     

                }
                else if ((JobClassID == 2)) //ABジョブ 
                {
                    if (DownloadID == 0)
                    {
                        JobClass = JobClassAll.A;
                    }
                    else if (DownloadID == 1)
                    {
                        JobClass = JobClassAll.B;
                    }
                }
                else if ((JobClassID == 3))
                {
                    JobClass = JobClassAll.D;
                }
                else if ((JobClassID == 4))
                {
                    JobClass = JobClassAll.E;
                }

            }


            else if (CategoryID == 12)
            {
                if (JobClassID == 9) //候補結果判定ジョブ
                {
                    if (DownloadID == 0)
                    {
                        JobClass = JobClassAll.α;
                    }
                    else if (DownloadID == 1)
                    {
                        JobClass = JobClassAll.β;
                    }


                }
            }
            else if (CategoryID == 13)
            {
               
                if ( (JobClassID == 10))
                {
                    // 新ABジョブ
                        if (DownloadID == 0)
                        {
                           JobClass = JobClassAll.A;
                        }
                        else if (DownloadID == 1)
                        {
                           JobClass = JobClassAll.B;
                        }
                }
                else if ( (JobClassID == 11))
                {
                      JobClass = JobClassAll.D;
                }
                else if ((JobClassID == 12))
                {
                    JobClass = JobClassAll.E;
                }
            }
            else if (CategoryID == 14)
            {
                if (JobClassID == 16)
                {
                    JobClass = JobClassAll.F;
                }
                else if (JobClassID == 17)
                {
                    JobClass = JobClassAll.G;
                }
            }

            //if (JobClass == JobClassAll.unKnow)
            //{
            //    string a = "";
            //}

            return JobClass;
        }

       

        #endregion

        #region 主线程消息传递

        private void writeMsg(string msg)
        {
            UI.showMessage showMsg = new UI.showMessage(ParentForm.ParentForm.showMessage);

            ParentForm.ParentForm.Invoke(showMsg, new Object[] { msg });
        }
        private void WriteMsgBar(string msg)
        {
            UI.SetMsgBar setMsgBar = new UI.SetMsgBar(ParentForm.ParentForm.SetMsgBar);

            ParentForm.ParentForm.Invoke(setMsgBar, new Object[] { msg });
        }
        private void SetProcessBarMain(int current, int Max)
        {
            UI.SetProcessBar setProcessBar = new UI.SetProcessBar( this.ParentForm.ParentForm.SetProcessBarMain);

            ParentForm.ParentForm.Invoke(setProcessBar, new Object[] { current, Max });

          
        }

        private void SetProcessBarBusy()
        {
            UI.normal normal = new UI.normal(ParentForm.ParentForm.SetProcessBarBusy);
            ParentForm.ParentForm.Invoke(normal);
          
        }
        private void SetProcessBarNormal()
        {
            UI.normal normal = new UI.normal(ParentForm.ParentForm.SetProcessBarNormal);
            ParentForm.ParentForm.Invoke(normal);
            ParentForm.ParentForm.SetProcessBarNormal();
        }


        #endregion

        #region 分解权限

        /// <summary>
        /// 权限分解
        /// </summary>
        public void DecomposeRolePerson()
        {
            if (workMode == WorkMode.Offline)
            {
                OfflineDecomposeRolePerson();
            }
            else
            {
                OnlineDecomposeRolePerson();
            }

            UI.DecompostiteFinish decompostiteFinish = new UI.DecompostiteFinish(this.ParentForm.OnDecompositionFinished);
            this.ParentForm.Invoke(decompostiteFinish);


        }


        private void OfflineDecomposeRolePerson()
        {
            DecomposeRolePerson(new Data.RoleLevelOffline(),
                                    new Data.OperatorRoleOffline());
        }

        private void OnlineDecomposeRolePerson()
        {
            DecomposeRolePerson(new Data.RoleLevelOnline(),
                                    new Data.OperatorRoleOnline());
        }

        #endregion

        #region 私有方法 获得权限数据

        private void DecomposeRolePerson(Data.RoleLevel roleLevel, Data.OperatorRole operatorRole)
        {
            try
            {
                WriteMsgBar("Get Role .....");

                writeMsg("Get roleLevels");
                List<Model.ModelRoleLevel> roleLevelList = roleLevel.GetRoleLevel();

                WriteMsgBar("Get Operator Role .....");
                writeMsg("Get operatorRoles");
                List<Model.ModelOperatorRole> operatorRoleList = operatorRole.GetOperatorRole();

                WriteMsgBar("Get Over ");

                SaveDecompositionData(roleLevelList, operatorRoleList);
            }
            catch (Exception ex)
            {
                string exMessage = "Exception : ";
                exMessage += Environment.NewLine;
                exMessage += ex.Message;
                Log.Error(exMessage, ex);

                throw ex;
            }

        }

        #endregion

        #region 权限写入数据库

        private void SaveDecompositionData(List<Model.ModelRoleLevel> roleLevelList, List<Model.ModelOperatorRole> operatorRoleList)
        {
            DecompositionDB.DataProvider DecompositionDBProvider = new DecompositionDB.DataProvider();
            WriteMsgBar("Save DB ");

            #region 删除上次分解数据

            writeMsg("DeletDB Star @" + System.DateTime.Now.ToLongTimeString());

            DecompositionDBProvider.RoleLevelsDelete(ServerAddress);
            DecompositionDBProvider.OperatorRolesDelete(ServerAddress);
         
            writeMsg("DeletDB End @" + System.DateTime.Now.ToLongTimeString());

            #endregion

            writeMsg("InsertDB Star @" + System.DateTime.Now.ToLongTimeString());

            int i, iCount;

            i = 0;
            iCount = roleLevelList.Count;

            foreach (var item in roleLevelList)
            {
                DecompositionDBProvider.RoleLevelsInsert(
                    item.RoleListID,
                    item.RoleID,
                    item.ParentID,
                    item.LevelName,
                    Convert.ToInt32(item.IsLastNode),
                    ServerAddress);

    
                SetProcessBarMain(i, iCount);
                i++;

            }

            i = 0;
            iCount = operatorRoleList.Count;
            foreach (var item in operatorRoleList)
            {
                DecompositionDBProvider.OperatorRolesInsert(
                    item.OperatorID,
                    item.RoleID,
                    ServerAddress);


                SetProcessBarMain(i, iCount);
                i++;

            }

            writeMsg("InsertDB End @" + System.DateTime.Now.ToLongTimeString());
            WriteMsgBar("Save DB Over ");
            WriteMsgBar(" ");

        }
        #endregion

        #region 获得数据库访问地址

        /// <summary>
        /// Gets the server address.
        /// </summary>
        /// <value>The server address.</value>
        private string ServerAddress
        {
            get { return Util.ServerAddress; }
        }

        #endregion
    }

}
